package cn.com.fssg.platform.base.handler.impl.gsl.jc;

import cn.com.fssg.platform.base.handler.InterfaceHandler;
import cn.com.fssg.platform.biz.BizUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.nio.charset.StandardCharsets;
import java.util.*;

/**
 * @Description: 工商联届次查询接口
 */
@Component
public class GslJcZwSelectListCtl implements InterfaceHandler {

    private NamedParameterJdbcTemplate jdbcTemplate = BizUtil.cur().tenantMainJdbcTemplate();

//    @Autowired
//    private NamedParameterJdbcTemplate jdbcTemplate;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Object run(HttpServletRequest request, JSONObject jsonObject) throws Exception {
        String querySql = "select * from gsl_jc_zw_user where gsl_session = :jcId order by create_date desc ";
        Map<String, Object> param = new HashMap<>();
        param.put("jcId", jsonObject.getString("jcId"));
        List<Map<String, Object>> list = jdbcTemplate.queryForList(querySql, param);
        if (list.isEmpty()) {
            String queryJcSql = "SELECT id,phone,company,gsl_post,job_state,username,is_cadre,rz_date,gsl_session,role_scope,parent_role_scope \n" +
                    "FROM gsl_zwinfo_v " +
                    "WHERE gsl_session=(" +
                    "  SELECT id FROM gsl_jc " +
                    "  WHERE del_flag='0'" +
                    "  ORDER BY create_date DESC" +
                    "  LIMIT 1" +
                    ")";
            list = jdbcTemplate.queryForList(queryJcSql, new HashMap<>());
        }
        //封装返回方法
        Map<String, Object> result = new HashMap<>();
        if(!list.isEmpty()) {
            result.put("count", list.size());
            result.put("dataList", list);
        }
        return result;
    }
}
